/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mobiwebinc.compconn.systray;

import com.mobiwebinc.compconn.Main;
import com.mobiwebinc.compconn.configuration.Constant;
import com.mobiwebinc.compconn.gui.MainMenu;
import java.awt.AWTException;
import java.awt.Image;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.net.URL;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author suraj
 */
public class WindowSysTray extends SysTray {

    public WindowSysTray() {
        init();
    }

    @Override
    public void init() {
        createTrayItem();
    }

    public void createTrayItem() {
        SystemTray tray = SystemTray.getSystemTray();
        URL url = null;
        try {
            url = Main.class.getResource("mobideskserver.png");
        } catch (Exception e) {
            System.out.println("icon image not found");
        }

        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } catch (InstantiationException e) {
        } catch (ClassNotFoundException e) {
        } catch (UnsupportedLookAndFeelException e) {
        } catch (IllegalAccessException e) {
        }
        Image IconImage = Toolkit.getDefaultToolkit().getImage(url);
        PopupMenu popup = MainMenu.getFullMenu().getPopupMenu();
        TrayIcon trayIcon = new TrayIcon(IconImage, Constant.PRODUCT_NAME, popup);
        trayIcon.setImageAutoSize(true);
        trayIcon.displayMessage(Constant.PRODUCT_NAME, "Started", TrayIcon.MessageType.INFO);
        try {
            tray.add(trayIcon);
        } catch (AWTException e) {
            System.err.println("TrayIcon could not be added.");
        }
    }
}
